package org.example.mybatis.mapper;

import org.apache.catalina.User;
import org.apache.ibatis.annotations.*;
import org.example.mybatis.model.UserInfo;

import java.util.List;

@Mapper
public interface UserInfoMapper {
    //查询所有的用户信息
    @Select("select * from user_info")
    List<UserInfo> selectAll();

    //非唯一主键查询,返回结果建议使用List
  //  @Select("select * from user_info where age= #{age} and gender = #{gender}")  //推荐写法
    @Select("select * from user_info where age = #{age} and gender = #{gender}")  //参数重命名 参数和注解名称保持一致

    List<UserInfo> selectUserByAgeAndGender(@Param("gender") Integer gender , @Param("age") Integer age );

    //传递对象
    @Insert("insert into user_info (username, `password`, age, gender) " +
            "values (#{username}, #{password}, #{age}, #{gender})")
    Integer insertUser(UserInfo userInfo);

    @Insert("insert into user_info (username, `password`, age, gender) " +
            "values (#{userInfo.username}, #{userInfo.password}, #{userInfo.age}, #{userInfo.gender})")
    Integer insertUserByParam(@Param("userInfo") UserInfo userInfo);

    //删除数据
    @Delete("delete from user_info where id = #{id}")
    Integer delete(Integer id);

   /* //修改数据
    @Update("update user_info set password = #{password} where id =#{id}")
    Integer update(Integer id, String password);
*/
    @Update("update user_info set password = #{password} where id =#{id}")
    Integer update(UserInfo userInfo);

    //#和 $的区别
    @Select("select * from user_info where id = ${id}")
    UserInfo selectUserById1(Integer id);
}
